package com.genertech.lms.controller;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.genertech.lms.model.User;
import com.genertech.lms.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/addRecord")
	public String showMessage(Model model){	
		User user = new User();
		user.setId(UUID.randomUUID().toString());
		user.setName("beijin");
		user.setAge(12);
		user.setAddress("通河新村");		
		logger.info("新增记录：{}条",userService.addRecord(user));		
		model.addAttribute("message","hello world!");		
		return "showMessage";
	}
	
	@RequestMapping("/findRecord")
	public String findRecord(Model model){		
		logger.info("找到记录：{}条",userService.getCounts());		
		model.addAttribute("message",userService);		
		return "showMessage";
	}
	
}
